package com.mmy.controller.visa;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.mmy.domain.sys.TSysUser;
import com.mmy.domain.visa.VVisaCollection;
import com.mmy.service.impl.visa.TVisaCollectionServiceImpl;
import com.mmy.service.impl.visa.TVisaOrderServiceImpl;

/**
 * 类的介绍：签证收集信息
 *
 * @author hanxl
 * @date 2020-07-23
 * @version 1.0
 */
@Controller
public class TVisaCollectionController {
	@Autowired
	TVisaCollectionServiceImpl tVisaCollectionServiceImpl;

	@Autowired
	TVisaOrderServiceImpl tVisaOrderServiceImpl;

	/* 显示签证材料整理 */
	@RequestMapping(value = "/toupdatevisacollection")
	public String toUpdateVisaCollection(HttpServletRequest request, Model m) {
		/* 获取该订单流水号 */
		int iID = Integer.parseInt(request.getParameter("iID"));
		int iVisaID = Integer.parseInt(request.getParameter("iVisaID"));
		/* 通过iID获得订单号 */
		String cOrderID = tVisaOrderServiceImpl.findByID(iID).getOrderID();
		/* 通过订单号获得材料整理表 */
		List<VVisaCollection> lstVisaCollection = tVisaCollectionServiceImpl.findByOrderID(cOrderID);
		m.addAttribute("collectionlist", lstVisaCollection);
		m.addAttribute("iID", iID);
		m.addAttribute("iVisaID", iVisaID);
		return "webbackground/visamanagement/collectionindex";
	}
	/* 修改提交状态 */

	@RequestMapping(value = "/toupdatesubmit")
	public String toUpdateSubmit(String checkList, HttpServletRequest request, Model model, HttpSession session) {
		/* 获取该订单流水号 */
		int iID = Integer.parseInt(request.getParameter("iID"));
		int iVisaID = Integer.parseInt(request.getParameter("iVisaID"));
		String[] checklist = checkList.split(",");
		List<Integer> lstID = new ArrayList<>();

		for (String str : checklist) {
			lstID.add(Integer.parseInt(str));
		}

		TSysUser tSysUser = (TSysUser) session.getAttribute("tSysUser");
		String UserName = tSysUser.getUserName();
		tVisaCollectionServiceImpl.updateSubmit(lstID, UserName);

		return "redirect:toupdatevisacollection?iID=" + iID + "&iVisaID=" + iVisaID;

	}

}
